import 'dart:math';
import 'dart:ui';

import 'package:event_bus/event_bus.dart';
import 'package:flutter/material.dart';
import 'package:wangziyi_app/constans/constans.dart';
import 'package:wangziyi_app/constans/toast.dart';
import 'package:wangziyi_app/main.dart';

import 'package:wangziyi_app/pages/cart_empty_page.dart';
import 'package:wangziyi_app/pages/classification_page.dart';
import 'package:wangziyi_app/pages/home_page.dart';
import 'package:wangziyi_app/pages/personal_page.dart';
import 'package:wangziyi_app/scoped_model/app_model.dart';
import 'package:wangziyi_app/scoped_model/app_theme_color_model.dart';
import 'package:wangziyi_app/utils/eventbus_utils.dart';

import 'package:wangziyi_app/widgets/navigation_icon_view.dart';
import 'package:flutter/services.dart';
import 'package:wakelock/wakelock.dart';

class home extends StatefulWidget {

  @override
  _homeState createState() => _homeState();
}

class _homeState extends State<home> {


  final _appBarTitle = ['首页', '分类', '购物车', '我的'];
  List<NavigationIconView> _navigationIconViews;
  var _currentIndex = 0;
  List<Widget> pages;

  @override
  void initState() {

    // TODO: implement initState
    super.initState();

    _navigationIconViews = [
      NavigationIconView(
          title: _appBarTitle[0],
          iconPath: 'assets/images/home.png',
          activeIconPath: 'assets/images/home-fill.png'),
      NavigationIconView(
          title: _appBarTitle[1],
          iconPath: 'assets/images/all.png',
          activeIconPath: 'assets/images/all-fill.png'),
      NavigationIconView(
          title: _appBarTitle[2],
          iconPath: 'assets/images/cart-Empty.png',
          activeIconPath: 'assets/images/cart-Empty-fill.png'),
      NavigationIconView(
          title: _appBarTitle[3],
          iconPath: 'assets/images/Customer management.png',
          activeIconPath: 'assets/images/Customer management-fill.png'),
    ];

      pages = [
        HomePage(),
        ClassificationPage(),
        CartEmptyPage(),
        PersonalPage()
      ];


  }

  @override
  Widget build(BuildContext context) {
    //获取屏幕高度
    final  size=MediaQuery.of(context).size;
    final double width=size.width;
    final double height=size.height;
    appMoel.increment(width,height);
    return
      Scaffold(

          body: pages[_currentIndex],
          //TODO 底部导航栏
          bottomNavigationBar: BottomNavigationBar(
            currentIndex: _currentIndex,
            items: _navigationIconViews.map((view) => view.item).toList(),
            type: BottomNavigationBarType.fixed,
            //点击事件
            onTap: (index) {
              //刷新UI
              setState(() {
                _currentIndex = index;
              });
            },
          ),

      );

  }

}
